package com.diipo.weibo;

import com.diipo.weibo.adapter.DetailsItemAdapter;
import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;

public class LinearLayoutForListView extends LinearLayout {

    private DetailsItemAdapter adapter;
    private OnClickListener onClickListener = null;

    public LinearLayoutForListView(Context context) {
    	super(context);
    	
    }
    
    public LinearLayoutForListView(Context context, AttributeSet attrs) {
    	super(context, attrs);
    	// TODO Auto-generated constructor stub
    	
    }
    /**
     * 绑定布局
     */
    public void bindLinearLayout() {
    	removeAllViews();
        int count = adapter.getCount();
        for (int i = 0; i < count; i++) {
            View v = adapter.getView(i, null, null);
            v.setOnClickListener(this.onClickListener);
            addView(v, i);
        }
        Log.v("countTAG", "" + count);
    }
    
    public void addFooterView(View v){
    	addView(v);
    }


    /**
     * 获取Adapter
     * 
     * @return adapter
     */
    public DetailsItemAdapter getAdpater() {
        return adapter;
    }

    /**
     * 设置数据
     * 
     * @param adpater
     */
    public void setAdapter(DetailsItemAdapter adpater) {
        this.adapter = adpater;
        bindLinearLayout();
    }

    /**
     * 获取点击事件
     * @return
     */
    public OnClickListener getOnclickListner() {
        return onClickListener;
    }

    /**
     * 设置点击事件
     * 
     * @param onClickListener
     */
    public void setOnclickLinstener(OnClickListener onClickListener) {
        this.onClickListener = onClickListener;
    }

}
